Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @RalfJung |
src/librustc_mir/interpret/memory.rs
Outdated
There was a problem hiding this comment.
Good thought, but I already took care of that in #70226 so this will just cause merge conflict. Better to not do this change.
src/librustc_mir/interpret/memory.rs
Outdated
There was a problem hiding this comment.
Please don't call size_hint twice.
There was a problem hiding this comment.
The following snippet copied from here does the right thing:
let (lower, upper) = src.size_hint();
let len = upper.expect("can only write bounded iterators");
assert_eq!(lower, len, "can only write iterators with a precise length");
src/librustc_mir/interpret/memory.rs
Outdated
There was a problem hiding this comment.
Hm... in this case we fail to check that the iterator is truly empty. And write_bytes above has the same bug in fact.
There was a problem hiding this comment.
The check that is needed here is something like
src.next().expect_none("iterator said it was empty but returned an element")
src/librustc_mir/interpret/memory.rs
Outdated
There was a problem hiding this comment.
This fails to check that the size_hint did not lie.
I think it is better to loop up to len and make sure the iterator did not lie:
for idx in 0..len {
let val = Scalar::from_u16(src.next().unwrap());
...
}|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
Please rebase, a PR just landed that conflicts with this one. |
|
☔ The latest upstream changes (presumably #70404) made this pull request unmergeable. Please resolve the merge conflicts. |
src/librustc_mir/interpret/memory.rs
Outdated
There was a problem hiding this comment.
After the loop, please make sure that the iterator is empty like here.
src/librustc_mir/interpret/memory.rs
Outdated
There was a problem hiding this comment.
| let offset_ptr = ptr.offset(Size::from_bytes(idx.checked_mul(2).unwrap()), &tcx)?; | |
| let offset_ptr = ptr.offset(Size::from_bytes(idx) * 2, &tcx)?; // `Size` multiplication |
RalfJung
left a comment
There was a problem hiding this comment.
Looking good. :) Please squash, then I'll r+.
|
I force-pushed the squashed commit. Thank you for all the reviews! 😸 |
|
@bors r+ |
|
📌 Commit 4538f89 has been approved by |
add 'fn write_u16s' to Memory Added new function `Memory::write_u16s`. Needed in `MIRI` for implementing helper function to write wide_str to memory (for Windows).
Rollup of 6 pull requests Successful merges: - rust-lang#70384 (Refactor object file handling) - rust-lang#70397 (add 'fn write_u16s' to Memory) - rust-lang#70413 (Fix incorrect pattern warning "unreachable pattern") - rust-lang#70428 (`error_bad_item_kind`: add help text) - rust-lang#70429 (Clean up E0459 explanation) - rust-lang#70437 (Miri float->int casts: be explicit that this is saturating) Failed merges: r? @ghost
Added new function
Memory::write_u16s. Needed inMIRIfor implementing helper function to write wide_str to memory (for Windows).